Umbraco 12 register form
# help-with-umbraco
g
Hi friends, I'm trying to create a custom registration form. I've created a new page (/register) with the following code in the views: @Html.ActionLink("Register", "RenderRegister", "Register"); Basically, this page displays a button that takes me to a form. I've created a controller with the ActionResults method Register and the RenderRegister method. In the code of the form's Partial View, I have: @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage @model RegisterViewModel @using Ikea.ViewModel; @using Ikea.Controllers; @using (Html.BeginUmbracoForm("HandleRegister")) { Add registration details @Html.AntiForgeryToken() @Html.LabelFor(x => x.FirstName) @Html.TextBoxFor(x=>x.FirstName, new {@class="form-control", @type="text"}) @Html.ValidationMessageFor(x=>x.FirstName) } Register 1 Register 2 None of the buttons are functional. They return "This page isn’t working right now. If the problem continues, contact the site owner." In the controller, I have another method, HandleRegister, with the following code: if (!ModelState.IsValid) { return null; } var newMember = Services.MemberService.CreateMember(vm.Username, vm.Email, $"{vm.FirstName} {vm.LastName}", "Member"); Services.MemberService.Save(newMember); Services.MemberService.CreateWithIdentity(vm.Username, vm.Email, vm.Password, "Normal User"); Services.MemberService.AssignRole(newMember.Id, "Normal User"); return View("HomePage");
p
@User May I suggest “friends” instead of "guys"? We use gender inclusive language in this Discord. 😀
g
I want to mention that the two submit buttons don't enter the HandleRegister method at all. However, a third button of type @Html.ActionLink("Register", "HandleRegister", "Register") enters the method but doesn't post the form values; vm is null. Do you have any idea how to solve this issue?Additionally, on the register page, my components like navbar and footer are not present. I'm waiting for your answers. Thank you.
d
There's a few things to mention here: - you definitely need to use the submit button - when your validation fails in the controller, instead of
null
, you should return
CurrentUmbracoPage()
. For that, your controller must inherit from
SurfaceController
- In my experience,
BeginUmbracoForm
works best if you pass the controller as a string - You shouldn't need to add an antiforgery token, that happens automatically unless explicitly disabled. Could you try these options perhaps?
4 Views